package my.cn.bdqn.life;

import java.util.Map;

import my.cn.bdqn.life.myconst.CMD;
import my.cn.bdqn.life.service.FreeService;

import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends Activity {
	private EditText userName, userPWD;
	private CheckBox remeberPWD, autoLogin;
	private boolean remeber, auto;
	public static Map<String, String> map;
	public static LoginActivity currentLogin = null;
	SharedPreferences sp;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		currentLogin = this;
		setContentView(R.layout.login_layout);
		sp = getSharedPreferences("freelife",
				MODE_PRIVATE);
		userName = (EditText) findViewById(R.id.userName);
		userPWD = (EditText) findViewById(R.id.userPwd);
		remeberPWD = (CheckBox) findViewById(R.id.rememberPwd);
		autoLogin = (CheckBox) findViewById(R.id.autoLogin);
	    remeberPWD.setChecked(sp.getBoolean("remeber", false));
	    autoLogin.setChecked(sp.getBoolean("auto", false));
	}

	public void cancel(View view) {
	}

	public void login(View view) {
		String name = userName.getText().toString();
		String password = userPWD.getText().toString();
		if ("".equals(name) || "".equals(password)) {
			Toast.makeText(this, R.string.input_null, 1).show();
		} else {
			
			String n=sp.getString("name", null);
			String p=sp.getString("password", null);
			if(name.equals(n)&&password.equals(p)){
				SharedPreferences.Editor editor=sp.edit();
				editor.putBoolean("remeber",remeberPWD.isChecked());
				editor.putBoolean("auto", autoLogin.isChecked());
				editor.commit();
				startActivity(new Intent(this,TabMainActivity.class));
			}else{
				Toast.makeText(this, R.string.input_error, 1).show();
			}
		}

	}

}
